import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/bottom_enter_page.dart';
import 'package:app/pages/timesheet_module/create_timesheet_module/create_timesheet_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

import '../../../common/app_theme.dart';
import '../../../common/colors.dart';

class CreateTimeSheetView extends GetView{


  CreateTimeSheetController controller = Get.put(CreateTimeSheetController());

  bool submit = false;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('创建工时单'),
      ),
      body:GetBuilder<CreateTimeSheetController>(builder: (_){
        return  Column(
          children: [
            Expanded(child: ListView(
              children: [
                Container(
                  color: Colors.white,
                  padding: EdgeInsets.only(left: 10),
                  child: TextField(
                    controller: controller.editingController,
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: '请输入名称'
                    ),
                  ),
                ),
                submit==false?SizedBox():controller.editingController.text==''?buildFieldError('请输入名称'):SizedBox(),

                SizedBox(height: 1,),
                GestureDetector(
                    onTap: () async {
                      controller.tapClickStartTime();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(10, 10, 5, 10),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("日期",style: appThemeData.textTheme.bodyText1,),
                          // SizedBox(height: 12,),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text('${controller.startTime}',style: appThemeData.textTheme.subtitle1,),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                    color: AppColor.smallTextColor,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.startTime=='请选择开始时间'?buildFieldError('请选择开始时间'):SizedBox(),

                SizedBox(height: 1,),
                GestureDetector(
                    onTap: () async {
                      controller.tapClickProject();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(10, 10, 5, 10),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("选择项目",style: appThemeData.textTheme.bodyText1,),
                          // SizedBox(height: 12,),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text('${controller.projectName}',style: appThemeData.textTheme.subtitle1,),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                    color: AppColor.smallTextColor,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.projectId==null?buildFieldError('请选择项目'):SizedBox(),

                SizedBox(height: 1,),
                GestureDetector(
                    onTap: () async {
                      // controller.tapClickStartTime();
                      controller.tapClickTask();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(10, 10, 5, 10),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("选择任务",style: appThemeData.textTheme.bodyText1,),
                          // SizedBox(height: 12,),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text('${controller.taskName}',style: appThemeData.textTheme.subtitle1,),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                    color: AppColor.smallTextColor,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.taskId==null?buildFieldError('请选择任务'):SizedBox(),


              ],
            )),
            Container(
              color: Colors.white,
              child:  BottomEnterPage(() {
                submit = true;
                controller.update();
                if(controller.editingController.text != ''&&controller.startTime!='请选择开始时间'&&
                    controller.projectId!=null&&controller.taskId != null){
                  controller.requestDataWithCreate();
                }


              }),
            )
          ],
        );
      }),
    );
  }
  Widget buildFieldError(errorType) {
    return Padding(padding: EdgeInsets.only(left: 15),child: Row(
      children: [
        // if(errors.contains(errorType))
        Expanded(
          child: Text(
              '${errorType}',
              textAlign: TextAlign.left,
              style: TextStyle(
                  color: Colors.red,
                  fontSize: 12
              )
          ),
        ),
      ],
    ),);
  }

}